#!/usr/bin/env python
#coding:utf-8

import sys
import os
import fnmatch

__author__ = 'wwq0327@gmail.com'

def index(dirs):
    '''目录搜索，返回搜索到的文件'''

    stack = [dirs]
    files = []
    while stack:
        dirs = stack.pop()
        for file in os.listdir(dirs):
            fullname = os.path.join(dirs, file)
            files.append(fullname)
            if os.path.isdir(fullname) and not os.path.islink(fullname):
                stack.append(fullname)
    #print files
    return files

def delfile(dir):
    '''删除相应文件的操作'''
    delfile = []
    for file in index(dir):
        if fnmatch.fnmatch(file, '*.py~'):
            delfile.append(file)
            print file
        else:
            print '没有找到*.py~文件'

if __name__ == '__main__':
    delfile('.')
